package com.demo.nio;

import java.nio.ByteBuffer;

/**
 * @author gy
 * @date 2022/5/14
 */
public class NIOByteBufferPutGet {
    public static void main(String[] args) {
        // 创建一个buffer
        ByteBuffer buffer = ByteBuffer.allocate(64);

        // 类型化方式放入数据
        buffer.putInt(100);
        buffer.putLong(9);
        buffer.putChar('哈');
        buffer.putShort((short) 4);

        // 取出
        buffer.flip();

        System.out.println();

        // 注意：按照顺序传入，按照顺序取出
        System.out.println(buffer.getInt());
        System.out.println(buffer.getLong());
        System.out.println(buffer.getChar());
        System.out.println(buffer.getShort());

    }
}
